import itchat
import os
import time





def sendMsg(message, boom_obj):
    try:
        itchat.send_msg(msg=message, toUserName=boom_obj)
        print('第%d次轰炸成功！')
    except Exception as e:
        print('第%d次轰炸失败！')

def sendImages(boom_obj, pictures):
    n = 0
    for picture in pictures:
        if n > 15:
            break
        filename = 'images/'+picture
        print(filename)
        try:
            itchat.send_image(filename, toUserName=boom_obj)
            print('%s轰炸成功！' % picture)
            time.sleep(5)
            n += 1    
        except Exception as e:
            print('%s轰炸失败！,%s' % (picture,e))

if __name__ == "__main__":
    pictures = os.listdir('images')
    itchat.auto_login(hotReload=True)
    boom_remark_name = input("输入你要轰炸的人的微信备注：")
    message = input("输入你要轰炸的内容：")
    boom_obj = itchat.search_friends(remarkName=boom_remark_name)[0]['UserName']
    # sendMsg(message, boom_obj)
    sendImages(boom_obj, pictures)


    
    
